/**   
 * Copyright © 2016 公司名. All rights reserved.
 * 
 * @Title: NoticeServiceImpl.java 
 * @Prject: LianniuManager
 * @Package: com.lianniu.mgr.baseService.notice.service.impl
 * @Description: TODO
 * @author: lzz   
 * @date: 2016年8月8日 上午8:50:51 
 * @version: V1.0   
 */
package com.lianniu.mgr.baseService.notice.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.lianniu.mgr.base.BaseResult;
import com.lianniu.mgr.baseService.notice.dao.INoticeDao;
import com.lianniu.mgr.baseService.notice.enums.NoticeStatusEnum;
import com.lianniu.mgr.baseService.notice.model.NoticeVo;
import com.lianniu.mgr.baseService.notice.service.INoticeService;
import com.lianniu.mgr.pagination.PaginationInfo;
import com.lianniu.mgr.baseService.notice.service.impl.NoticeServiceImpl;

/** 
 * @ClassName: NoticeServiceImpl 
 * @Description: TODO
 * @author: lzz
 * @date: 2016年8月8日 上午8:50:51  
 */
@Service("noticeService")
public class NoticeServiceImpl implements INoticeService{
    public static final Logger logger = Logger.getLogger(NoticeServiceImpl.class);
    
    @Resource
    private INoticeDao noticeDao;
    @Override
    public BaseResult getNoticeList(NoticeVo noticeVo, PaginationInfo paginationInfo) {
        logger.info("NoticeServiceImpl getNoticeList begin.");
        noticeVo.setPaginationInfo(paginationInfo);
        logger.info("NoticeServiceImpl getNoticeList getNoticeListForPage begin.");
        List<NoticeVo> list = noticeDao.getNoticeListForPage(noticeVo);
        logger.info("NoticeServiceImpl getNoticeList getNoticeListForPage end.");
        Map<String, Object> reMap = new HashMap<>();
        reMap.put("total", paginationInfo.getTotalRecord());
        reMap.put("curPage", paginationInfo.getCurPage());    
        reMap.put("rows", list);
        BaseResult result = BaseResult.success(reMap);
        logger.info("NoticeServiceImpl getNoticeList end.");
        return result;
    }

    @Override
    public BaseResult getNotice(long noticeId) {
        logger.info("NoticeServiceImpl getNotice begin.");
        logger.info("NoticeServiceImpl getNotice getNoticeById begin.");
        NoticeVo noticeVo = noticeDao.getNoticeById(noticeId);
        logger.info("NoticeServiceImpl getNotice getNoticeById end.");
        BaseResult result = BaseResult.success(noticeVo);
        logger.info("NoticeServiceImpl getNotice end.");
        return result;
    }

    @Override
    public BaseResult pushNotice(NoticeVo noticeVo) {
        logger.info("NoticeServiceImpl pushNotice begin.");
        logger.info("NoticeServiceImpl pushNotice addNotice begin.");
        noticeVo.setDelFlag(NoticeStatusEnum.NOTDEL.getCode());
        Integer i = noticeDao.addNotice(noticeVo);
        logger.info("NoticeServiceImpl pushNotice addNotice end.");
        BaseResult result = BaseResult.success(i);
        logger.info("NoticeServiceImpl pushNotice end.");
        return result;
    }

    @Override
    public BaseResult saveNotice(NoticeVo noticeVo) {
        logger.info("NoticeServiceImpl saveNotice begin.");
        logger.info("NoticeServiceImpl saveNotice editNotice begin.");
        Integer i = noticeDao.editNotice(noticeVo);
        logger.info("NoticeServiceImpl saveNotice editNotice end.");
        BaseResult result = BaseResult.success(i);
        logger.info("NoticeServiceImpl saveNotice end.");
        return result;
    }

    @Override
    public BaseResult delNotice(long noticeId) {
        logger.info("NoticeServiceImpl delNotice begin.");
        logger.info("NoticeServiceImpl delNotice delNotice begin.");
        NoticeVo noticeVo = new NoticeVo();
        noticeVo.setId(noticeId);
        noticeVo.setDelFlag(NoticeStatusEnum.DELED.getCode());
        Integer i = noticeDao.delNotice(noticeVo);
        logger.info("NoticeServiceImpl delNotice delNotice end.");
        BaseResult result = BaseResult.success(i);
        logger.info("NoticeServiceImpl delNotice end.");
        return result;
    }


}
